home *** CD-ROM | disk | FTP | other *** search
/ Champak 50 / Volume 50 - JOGO DISK .iso / Games / moonstonemadness.swf / scripts / __Packages / Library / Sound / SoundManager.as < prev   
Text File  |  2007-09-27  |  9KB  |  267 lines

  1. class Library.Sound.SoundManager
  2. {
  3.    static var EVENT_SOUND_COMPLETE = 1;
  4.    static var DEFAULT_CATEGORY = "SFX";
  5.    static var MAX_SOUNDS_PLAYING = 8;
  6.    static var bInited = false;
  7.    function SoundManager()
  8.    {
  9.    }
  10.    static function doPlaySound(__sLinkage, __nVolume, __nLoop, __bUnique)
  11.    {
  12.       return Library.Sound.SoundManager.doPlaySoundInCat(Library.Sound.SoundManager.DEFAULT_CATEGORY,__sLinkage,__nVolume,__nLoop,__bUnique);
  13.    }
  14.    static function doPlaySoundInCat(__sCategoryName, __sLinkage, __nVolume, __nLoop, __bUnique)
  15.    {
  16.       Library.Sound.SoundManager.doCheckInit();
  17.       var _loc1_ = undefined;
  18.       if(Library.Sound.SoundManager.__get__NewSoundAllowed())
  19.       {
  20.          if(__nVolume == undefined)
  21.          {
  22.             __nVolume = 100;
  23.          }
  24.          if(__nLoop == undefined)
  25.          {
  26.             __nLoop = 1;
  27.          }
  28.          if(__bUnique == undefined)
  29.          {
  30.             __bUnique = false;
  31.          }
  32.          var _loc2_ = undefined;
  33.          if(__bUnique)
  34.          {
  35.             var _loc4_ = Library.Sound.SoundManager.isSoundPlaying(__sLinkage);
  36.             if(_loc4_.bPlaying)
  37.             {
  38.                _loc2_ = false;
  39.                _loc1_ = _loc4_.oSound;
  40.             }
  41.             else
  42.             {
  43.                _loc2_ = true;
  44.             }
  45.          }
  46.          else
  47.          {
  48.             _loc2_ = true;
  49.          }
  50.          if(_loc2_)
  51.          {
  52.             Library.Sound.SoundManager.doManageCategory(__sCategoryName);
  53.             var _loc5_ = Library.Sound.SoundManager.getMCForSound();
  54.             var _loc3_ = new Sound(_loc5_);
  55.             _loc3_.attachSound(__sLinkage);
  56.             if(_loc3_.duration != undefined)
  57.             {
  58.                _loc1_ = new Library.Sound.SoundItem(_loc3_,__sLinkage,__nVolume,__nLoop,__sCategoryName,_loc5_);
  59.             }
  60.             _loc1_.doAddListener(Library.Sound.SoundManager);
  61.             Library.Sound.SoundManager.aSounds.push(_loc1_);
  62.          }
  63.       }
  64.       return _loc1_;
  65.    }
  66.    static function isSoundPlaying(__sLinkageName)
  67.    {
  68.       var _loc1_ = new Object();
  69.       _loc1_.bPlaying = false;
  70.       _loc1_.oSound = undefined;
  71.       for(var _loc3_ in Library.Sound.SoundManager.aSounds)
  72.       {
  73.          if(Library.Sound.SoundManager.aSounds[_loc3_].LinkageName == __sLinkageName)
  74.          {
  75.             _loc1_.oSound = Library.Sound.SoundManager.aSounds[_loc3_];
  76.             _loc1_.bPlaying = true;
  77.          }
  78.       }
  79.       return _loc1_;
  80.    }
  81.    static function doManageExternalSound(__oSound)
  82.    {
  83.       Library.Sound.SoundManager.doCheckInit();
  84.       Library.Sound.SoundManager.doManageCategory(__oSound.__get__Category());
  85.       __oSound.doAddListener(Library.Sound.SoundManager);
  86.       Library.Sound.SoundManager.aSounds.push(__oSound);
  87.    }
  88.    static function getMCForSound()
  89.    {
  90.       var _loc1_ = Library.Sound.SoundManager.getNextDepth();
  91.       var _loc2_ = Library.Sound.SoundManager.mcAttach.createEmptyMovieClip("Snd" + _loc1_,_loc1_);
  92.       return _loc2_;
  93.    }
  94.    static function getNextDepth()
  95.    {
  96.       Library.Sound.SoundManager.nSoundNum = Library.Sound.SoundManager.nSoundNum + 1;
  97.       return Library.Sound.SoundManager.nSoundNum;
  98.    }
  99.    static function get SoundsQty()
  100.    {
  101.       return Library.Sound.SoundManager.aSounds.length;
  102.    }
  103.    static function doInit(__mcAttach)
  104.    {
  105.       Library.Sound.SoundManager.mcAttach = __mcAttach;
  106.       if(!Library.Sound.SoundManager.bInited)
  107.       {
  108.          Library.Sound.SoundManager.bInited = true;
  109.          Library.Sound.SoundManager.nSoundNum = 0;
  110.          Library.Sound.SoundManager.aSounds = new Array();
  111.          Library.Sound.SoundManager.aSoundCategories = new Array();
  112.          Library.Sound.SoundManager.nMasterVolume = 100;
  113.          _global.mx.transitions.OnEnterFrameBeacon.init();
  114.          Library.Sound.SoundManager.oEnterFrameListener = new Object();
  115.          Library.Sound.SoundManager.oEnterFrameListener.onEnterFrame = Library.Utils.Delegate.create(Library.Sound.SoundManager,Library.Sound.SoundManager.doEnterFrame);
  116.          MovieClip.addListener(Library.Sound.SoundManager.oEnterFrameListener);
  117.       }
  118.    }
  119.    static function doEnterFrame()
  120.    {
  121.       for(var _loc1_ in Library.Sound.SoundManager.aSounds)
  122.       {
  123.          Library.Sound.SoundManager.aSounds[_loc1_].doEnterFrame();
  124.       }
  125.    }
  126.    static function setCategoryVolume(__sCategoryName, __nVol)
  127.    {
  128.       Library.Sound.SoundManager.doManageCategory(__sCategoryName);
  129.       for(var _loc3_ in Library.Sound.SoundManager.aSoundCategories)
  130.       {
  131.          if(Library.Sound.SoundManager.aSoundCategories[_loc3_].sName == __sCategoryName)
  132.          {
  133.             Library.Sound.SoundManager.aSoundCategories[_loc3_].nVolume = __nVol;
  134.          }
  135.       }
  136.       Library.Sound.SoundManager.doUpdateAllSoundsVolume();
  137.    }
  138.    static function getCategoryVolume(__sCategoryName)
  139.    {
  140.       Library.Sound.SoundManager.doManageCategory(__sCategoryName);
  141.       var _loc1_ = undefined;
  142.       for(var _loc3_ in Library.Sound.SoundManager.aSoundCategories)
  143.       {
  144.          if(Library.Sound.SoundManager.aSoundCategories[_loc3_].sName == __sCategoryName)
  145.          {
  146.             _loc1_ = Library.Sound.SoundManager.aSoundCategories[_loc3_].nVolume;
  147.          }
  148.       }
  149.       return _loc1_;
  150.    }
  151.    static function isCategoryMuted(__sCategoryName)
  152.    {
  153.       Library.Sound.SoundManager.doManageCategory(__sCategoryName);
  154.       var _loc1_ = undefined;
  155.       for(var _loc3_ in Library.Sound.SoundManager.aSoundCategories)
  156.       {
  157.          if(Library.Sound.SoundManager.aSoundCategories[_loc3_].sName == __sCategoryName)
  158.          {
  159.             _loc1_ = Library.Sound.SoundManager.aSoundCategories[_loc3_].bMuted;
  160.          }
  161.       }
  162.       return _loc1_;
  163.    }
  164.    static function doSoundEvent(__nEvent, __oSound)
  165.    {
  166.       if(__nEvent === Library.Sound.SoundManager.EVENT_SOUND_COMPLETE)
  167.       {
  168.          var _loc1_ = false;
  169.          for(var _loc3_ in Library.Sound.SoundManager.aSounds)
  170.          {
  171.             if(!_loc1_)
  172.             {
  173.                if(Library.Sound.SoundManager.aSounds[_loc3_] == __oSound)
  174.                {
  175.                   _loc1_ = true;
  176.                   delete Library.Sound.SoundManager.aSounds[_loc3_];
  177.                   Library.Sound.SoundManager.aSounds.splice(Number(_loc3_),1);
  178.                }
  179.             }
  180.          }
  181.       }
  182.    }
  183.    static function doMuteCategory(__sCategoryName)
  184.    {
  185.       for(var _loc2_ in Library.Sound.SoundManager.aSoundCategories)
  186.       {
  187.          if(Library.Sound.SoundManager.aSoundCategories[_loc2_].sName == __sCategoryName)
  188.          {
  189.             Library.Sound.SoundManager.aSoundCategories[_loc2_].bMuted = true;
  190.          }
  191.       }
  192.       Library.Sound.SoundManager.doUpdateAllSoundsVolume();
  193.    }
  194.    static function doUnMuteCategory(__sCategoryName)
  195.    {
  196.       for(var _loc2_ in Library.Sound.SoundManager.aSoundCategories)
  197.       {
  198.          if(Library.Sound.SoundManager.aSoundCategories[_loc2_].sName == __sCategoryName)
  199.          {
  200.             Library.Sound.SoundManager.aSoundCategories[_loc2_].bMuted = false;
  201.          }
  202.       }
  203.       Library.Sound.SoundManager.doUpdateAllSoundsVolume();
  204.    }
  205.    static function setMasterVolume(__nVol)
  206.    {
  207.       Library.Sound.SoundManager.nMasterVolume = __nVol;
  208.       Library.Sound.SoundManager.doUpdateAllSoundsVolume();
  209.    }
  210.    static function get NewSoundAllowed()
  211.    {
  212.       return Library.Sound.SoundManager.aSounds.length < Library.Sound.SoundManager.MAX_SOUNDS_PLAYING;
  213.    }
  214.    static function get MasterVolume()
  215.    {
  216.       return Library.Sound.SoundManager.nMasterVolume;
  217.    }
  218.    static function doRemoveListenerFromAllSounds(__oListener)
  219.    {
  220.       for(var _loc2_ in Library.Sound.SoundManager.aSounds)
  221.       {
  222.          Library.Sound.SoundManager.aSounds[_loc2_].doRemoveListener(__oListener);
  223.       }
  224.    }
  225.    static function doDestroy()
  226.    {
  227.       Library.Sound.SoundManager.doRemoveListenerFromAllSounds();
  228.       for(var _loc1_ in Library.Sound.SoundManager.aSounds)
  229.       {
  230.          Library.Sound.SoundManager.aSounds[_loc1_].doDestroy();
  231.       }
  232.    }
  233.    static function doUpdateAllSoundsVolume()
  234.    {
  235.       for(var _loc1_ in Library.Sound.SoundManager.aSounds)
  236.       {
  237.          Library.Sound.SoundManager.aSounds[_loc1_].doUpdateSound();
  238.       }
  239.    }
  240.    static function doCheckInit()
  241.    {
  242.       if(Library.Sound.SoundManager.bInited)
  243.       {
  244.       }
  245.    }
  246.    static function doManageCategory(__sCategoryName)
  247.    {
  248.       Library.Sound.SoundManager.doCheckInit();
  249.       var _loc1_ = false;
  250.       for(var _loc4_ in Library.Sound.SoundManager.aSoundCategories)
  251.       {
  252.          if(Library.Sound.SoundManager.aSoundCategories[_loc4_].sName == __sCategoryName)
  253.          {
  254.             _loc1_ = true;
  255.          }
  256.       }
  257.       if(!_loc1_)
  258.       {
  259.          var _loc3_ = new Object();
  260.          _loc3_.sName = __sCategoryName;
  261.          _loc3_.nVolume = 100;
  262.          _loc3_.bMuted = false;
  263.          Library.Sound.SoundManager.aSoundCategories.push(_loc3_);
  264.       }
  265.    }
  266. }
  267.